package com.situ.day7;

import org.junit.Test;

import java.util.*;

public class CollectionDemo {

    @Test
    public void test1() {
        int[] array1 = {3, 4, 65};
        int[] array2 = new int[3];
        Student[] array = new Student[3];

        // 数组最大的问题是长度固定
        // ArrayList底层使用Array数组实现的，是对数组的封装，添加、遍历元素时候可以不用考虑下标
        ArrayList<Student> list = new ArrayList();
        Student student1 = new Student(1, "zhansgan1", 23, "男");
        Student student2 = new Student(2, "zhansgan2", 23, "男");
        Student student3 = new Student(3, "zhansgan3", 23, "男");
        list.add(student1);
        list.add(student2);
        list.add(student3);
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println(student);
        }
        // foreach
        for (Student student : list) {
            System.out.println(student);
        }

    }

    @Test
    public void test3() {
        ArrayList list = new ArrayList();
        list.add("abc");
        list.add(23);

        ArrayList<Integer> list1 = new ArrayList();
        list1.add(23);
        list1.add(5);
        // list1.add("ac");
    }

    // ArrayList  HashSet   HashMap
    @Test
    public void test33() {
        // ArrayList<Student> list = new ArrayList();
        List<Student> list = new ArrayList<>();
        Student student1 = new Student(1, "zhansgan1", 23, "男");
        Student student2 = new Student(2, "zhansgan2", 23, "男");
        Student student3 = new Student(3, "zhansgan3", 23, "男");
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student1);
        for (Student student : list) {
            System.out.println(student);
        }
        System.out.println("--------------");
        HashSet<Student> set = new HashSet<Student>();
        set.add(student1);
        set.add(student2);
        set.add(student3);
        set.add(student1);
        for (Student student : set) {
            System.out.println(student);
        }
    }

    @Test
    public void test55() {
        Map<String, String> map = new HashMap();
        map.put("cn", "中华人民共和国");
        map.put("us", "合众国");
        map.put("uk", "大不列颠");
        System.out.println(map.get("cn"));

        // Entry:条目，是对key-value封装
        // Map.Entry<String, String> entry;
        int[] array = {3, 4,5 };
        for (int item : array) {

        }

        Set<Map.Entry<String, String>> set = map.entrySet();
        for (Map.Entry entry : set) {
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }

        System.out.println("-----------");
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            System.out.println(key + " : " + map.get(key));
        }
    }

    @Test
    public void test444() {
        String str = "abc";
        // isSearchByIdFound
        boolean bool1 = "".isEmpty();
        System.out.println(bool1);
        boolean bool2 = "abc".isEmpty();
    }
}
